package com.leo.ibatis.demo.service.impl;

import java.util.List;

import com.leo.ibatis.demo.base.Service;
import com.leo.ibatis.demo.criteria.CategoryCriteria;
import com.leo.ibatis.demo.dao.CategoryDao;
import com.leo.ibatis.demo.domain.Category;
import com.leo.ibatis.demo.service.CategoryService;

public class CategoryServiceImpl extends Service implements CategoryService {

	private CategoryDao categoryDao;

	public void setCategoryDao(CategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

	public void insert(Category category) {
		categoryDao.insert(category);
	}

	public int update(Category category) {
		int actualRowsAffected = 0;
		
		String catid = category.getCatid();

		Category _oldCategory = categoryDao.select(catid);
		
		if (_oldCategory != null) {
			actualRowsAffected = categoryDao.update(category);
		}
		
		return actualRowsAffected;
	}

	public int delete(String catid) {
		int actualRowsAffected = 0;
		
		Category _oldCategory = categoryDao.select(catid);
		
		if (_oldCategory != null) {
			actualRowsAffected = categoryDao.delete(catid);
		}
		
		return actualRowsAffected;
	}
	
	public Category select(String catid) {
		return categoryDao.select(catid);
	}

	public List<Category> list(CategoryCriteria categoryCriteria) {
		return categoryDao.list(categoryCriteria);
	}
	
	public List<Category> listOnPage(CategoryCriteria categoryCriteria) {
		return categoryDao.listOnPage(categoryCriteria);
	}

}
